package com.linhh.mall.center.server.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linhh.mall.center.api.UserInfoService;
import com.linhh.mall.center.common.pojo.UserInfo;
import com.linhh.mall.center.server.mappers.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Author linhh
 * @Date 2022 10 09 02 22
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public List<UserInfo> selectAll() {
        return userInfoMapper.selectAll();
    }

    @Override
    public int addUserInfo(UserInfo userInfo) {
        userInfoMapper.insertSelective(userInfo);
        return 1;
    }

    @Override
    public int deleteUserInfo(Long id) {
        userInfoMapper.deleteByPrimaryKey(id);
        return 1;
    }

    @Override
    public int updateUserInfo(UserInfo userInfo) {
        userInfoMapper.updateByPrimaryKeySelective(userInfo);
        return 1;
    }

    @Override
    public UserInfo findByUserName(String userName) {
        Example example = new Example(UserInfo.class);
        example.createCriteria().andEqualTo("userName", userName);
        UserInfo userInfo = userInfoMapper.selectOneByExample(example);
        return userInfo;
    }

    @Override
    public PageInfo<UserInfo> selectPageInfo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<UserInfo> userInfoList = userInfoMapper.selectAll();
        PageInfo<UserInfo> userInfoPageInfo = new PageInfo<>(userInfoList);
        return userInfoPageInfo;
    }
}
